package dao;

import java.util.ArrayList;
import java.util.List;



import modele.Theme;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import services.persistance.BaseDAO;

public class ThemeDao {

	public static void ajouterTheme(Theme theme) {
		BaseDAO.getInstance().ajouter(theme);
	}

	public static void modifierTheme(Theme theme) {
		BaseDAO.getInstance().modifier(theme);
	}

	public static void supprimerTheme(Theme theme) {
		BaseDAO.getInstance().supprimer(theme);
	}

	public static Theme getTheme(long idTheme) {
		return (Theme) BaseDAO.getInstance().getObject(Theme.class, idTheme);
	}
	
	public static List getListeThemes(long idAdmin)
	{
		List liste = new ArrayList<>();
		liste.add(idAdmin);
		return BaseDAO.getInstance().getListObject("queryListeThemes",liste);
	}
	
	public static ArrayList<Theme> rechercherThemesParCriteresParAdmin(Theme theme)
	{
		Criteria criteria = BaseDAO.getInstance().getSession().createCriteria(Theme.class);
		criteria.add(Restrictions.like("description", "%"+ theme.getDescription() +"%"));
		
		criteria.createCriteria("administrateur").add(Restrictions.eq("identifiant", theme.getAdministrateur().getIdentifiant()));
		
		return (ArrayList<Theme>) BaseDAO.getInstance().getListObjectByCriteria(criteria);
	}

	
}
